// pages/home/home.js
var app = getApp();
var userId;
var url = app.globalData.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop:0,
    floorstatus:false,
    URL: app.globalData.url,
    category:[],
    imgUrls: [],
    choiceness:[],
    category_list:[],
    indicatorDots: true,
    autoplay: true,
    interval:2500,
    duration:500
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    userId = wx.getStorageSync('user_id');
    var that = this;
    wx.request({
      url: url + "/api/index/index",
      success:function(res){
        // console.log(res);
        that.setData({
          imgUrls: res.data.inslide,
          category: res.data.category,
          choiceness: res.data. choiceness,
          category_list: res.data.category_list,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  searchsubmit:function(i){
    console.log(i.detail.value.search);
    wx.navigateTo({
      url: '/pages/goodsList/goodsList?keyword=' + i.detail.value.search,
    })
  },
  navClick:function(e){
    // console.log(e);
    wx.navigateTo({
      url: '/pages' + e.currentTarget.dataset.link,
    })
  },
  categorySubmit:function(t){
    console.log(t);
    wx.navigateTo({
      url: '/pages/goodsList/goodsList?id=' + t.currentTarget.id,
    })
  },
  choicenessSubmit:function(b){
    console.log(b);
    wx.navigateTo({
      url: '/pages' + b.currentTarget.dataset.link,
    })
  },
  category_list_advSubmit:function(c){
    wx.navigateTo({
      url: '/pages' + c.currentTarget.dataset.link,
    })
  },
  goodsInfoSubmit:function(f){
    console.log(f);
    wx.navigateTo({
      url: '/pages/goodsInfo/goodsInfo?id=' + f.currentTarget.id,
    })
  },
  moreSubmit:function(i){
    wx.navigateTo({
      url: '/pages/goodsList/goodsList?id=' + i.currentTarget.id,
    })
  },
  cartSubmit:function(){
    wx.switchTab({
      url: '/pages/cart/cart'
    })
  },
  orderSubmit:function(){
    wx.navigateTo({
      url: '/pages/orderlist/orderlist',
    })
  },
  topSubmit:function(){
    this.setData({
      scrollTop: 0
    })
  },
  scroll:function(a){
    if (a.detail.scrollTop > 500) {
      this.setData({
        floorstatus: true
      });
    } else {
      this.setData({
        floorstatus: false
      });
    }
  },
})